﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_ABPOSFS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void InsertICC_ABPOSFS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO ICC_ABPOSFS(KRS, LFD, SEASON, SECTION, ART, VAR, FARBE, PHOTO, CDES, ARTDES, EXTPRODUCER, STARTDAT, DELDAT, ETDDAT, AETDDAT, CAPP, SMAPP, SZAPP, WAPP1, WAPP2, WAPP3, WAPP4, WAPP5, WAPP6, WAPP7, WAPP8, AAPP1, AAPP2, AAPP3, AAPP4, AAPP5, AAPP6, AAPP7, AAPP8, WCHECK, EXTTECH, FPRICE, TQTY, REMARK, S, M, L, XL)"
                + "VALUES (:KRS,:LFD, null, '          ', :ART, :VAR, :FARBE, '23406090205         .JPG                                                                                                                                                                                ', null, null, '00000011  ', 20130826, 20130920, 0, 0, '   ', '   ', '   ', '   ', '   ', '   ', '   ', '   ', '   ', '   ', '   ', null, null, null, null, null, null, null, null, null, null, 0, 0, null, 0, 0, 0, 0)";
            or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
            or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
            or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
            or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
            or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_ABPOSFS(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_ABPOSFS WHERE  "
                    + "  KRS=:KRS AND LFD=:LFD AND FARBE=:FARBE";
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_ABPOSFS WHERE DELDAT>'20130808' ";
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ICC_ABPOSFS WHERE  "
                    + "  KRS=:KRS AND LFD=:LFD";
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    break;
                default:
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "ICC_ABPOSFS";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void SaveICC_ABPOSFS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_ABPOSFS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_ABPOSFS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_ABPOSFS(dwLocal, ITXDBVERSION);
            }
            UpdateICC_ABPOSFS(dwLocal, 1);
        }
        public void UpdateICC_ABPOSFS(DataRow dwData, int option, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE ICC_ABPOSFS SET "
                        + "KRS=:KRS,"
                        + "LFD=:LFD,"
                        + "SEASON=:SEASON,"
                        + "SECTION=:SECTION,"
                        + "ART=:ART,"
                        + "VAR=:VAR,"
                        + "FARBE=:FARBE,"
                        + "PHOTO=:PHOTO,"
                        + "CDES=:CDES,"
                        + "ARTDES=:ARTDES,"
                        + "EXTPRODUCER=:EXTPRODUCER,"
                        + "STARTDAT=:STARTDAT,"
                        + "DELDAT=:DELDAT,"
                        + "ETDDAT=:ETDDAT,"
                        + "AETDDAT=:AETDDAT,"
                        + "CAPP=:CAPP,"
                        + "SMAPP=:SMAPP,"
                        + "SZAPP=:SZAPP,"
                        + "WAPP1=:WAPP1,"
                        + "WAPP2=:WAPP2,"
                        + "WAPP3=:WAPP3,"
                        + "WAPP4=:WAPP4,"
                        + "WAPP5=:WAPP5,"
                        + "WAPP6=:WAPP6,"
                        + "WAPP7=:WAPP7,"
                        + "WAPP8=:WAPP8,"
                        + "AAPP1=:AAPP1,"
                        + "AAPP2=:AAPP2,"
                        + "AAPP3=:AAPP3,"
                        + "AAPP4=:AAPP4,"
                        + "AAPP5=:AAPP5,"
                        + "AAPP6=:AAPP6,"
                        + "AAPP7=:AAPP7,"
                        + "AAPP8=:AAPP8,"
                        + "WCHECK=:WCHECK,"
                        + "EXTTECH=:EXTTECH,"
                        + "FPRICE=:FPRICE,"
                        + "TQTY=:TQTY,"
                        + "REMARK=:REMARK,"
                        + "S=:S,"
                        + "M=:M,"
                        + "L=:L,"
                        + "XL=:XL"
                        + " WHERE  "
                        + "  KRS=:KRS AND LFD=:LFD AND  ART=:ART AND VAR=:VAR AND FARBE=:FARBE ";
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    or1.Parameters.Add("SEASON", OracleType.NVarChar).Value = dwData["SEASON"].ToString();
                    or1.Parameters.Add("SECTION", OracleType.NVarChar).Value = dwData["SECTION"].ToString();
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString();
                    or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"].ToString();
                    or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"].ToString();
                    or1.Parameters.Add("PHOTO", OracleType.NVarChar).Value = dwData["PHOTO"].ToString();
                    or1.Parameters.Add("CDES", OracleType.NVarChar).Value = dwData["CDES"].ToString();
                    or1.Parameters.Add("ARTDES", OracleType.NVarChar).Value = dwData["ARTDES"].ToString();
                    or1.Parameters.Add("EXTPRODUCER", OracleType.NVarChar).Value = dwData["EXTPRODUCER"].ToString();
                    or1.Parameters.Add("STARTDAT", OracleType.NVarChar).Value = dwData["STARTDAT"].ToString();
                    or1.Parameters.Add("DELDAT", OracleType.NVarChar).Value = dwData["DELDAT"].ToString();
                    or1.Parameters.Add("ETDDAT", OracleType.NVarChar).Value = dwData["ETDDAT"].ToString();
                    or1.Parameters.Add("AETDDAT", OracleType.NVarChar).Value = dwData["AETDDAT"].ToString();
                    or1.Parameters.Add("CAPP", OracleType.NVarChar).Value = dwData["CAPP"].ToString();
                    or1.Parameters.Add("SMAPP", OracleType.NVarChar).Value = dwData["SMAPP"].ToString();
                    or1.Parameters.Add("SZAPP", OracleType.NVarChar).Value = dwData["SZAPP"].ToString();
                    or1.Parameters.Add("WAPP1", OracleType.NVarChar).Value = dwData["WAPP1"].ToString();
                    or1.Parameters.Add("WAPP2", OracleType.NVarChar).Value = dwData["WAPP2"].ToString();
                    or1.Parameters.Add("WAPP3", OracleType.NVarChar).Value = dwData["WAPP3"].ToString();
                    or1.Parameters.Add("WAPP4", OracleType.NVarChar).Value = dwData["WAPP4"].ToString();
                    or1.Parameters.Add("WAPP5", OracleType.NVarChar).Value = dwData["WAPP5"].ToString();
                    or1.Parameters.Add("WAPP6", OracleType.NVarChar).Value = dwData["WAPP6"].ToString();
                    or1.Parameters.Add("WAPP7", OracleType.NVarChar).Value = dwData["WAPP7"].ToString();
                    or1.Parameters.Add("WAPP8", OracleType.NVarChar).Value = dwData["WAPP8"].ToString();
                    or1.Parameters.Add("AAPP1", OracleType.NVarChar).Value = dwData["AAPP1"].ToString();
                    or1.Parameters.Add("AAPP2", OracleType.NVarChar).Value = dwData["AAPP2"].ToString();
                    or1.Parameters.Add("AAPP3", OracleType.NVarChar).Value = dwData["AAPP3"].ToString();
                    or1.Parameters.Add("AAPP4", OracleType.NVarChar).Value = dwData["AAPP4"].ToString();
                    or1.Parameters.Add("AAPP5", OracleType.NVarChar).Value = dwData["AAPP5"].ToString();
                    or1.Parameters.Add("AAPP6", OracleType.NVarChar).Value = dwData["AAPP6"].ToString();
                    or1.Parameters.Add("AAPP7", OracleType.NVarChar).Value = dwData["AAPP7"].ToString();
                    or1.Parameters.Add("AAPP8", OracleType.NVarChar).Value = dwData["AAPP8"].ToString();
                    or1.Parameters.Add("WCHECK", OracleType.NVarChar).Value = dwData["WCHECK"].ToString();
                    or1.Parameters.Add("EXTTECH", OracleType.NVarChar).Value = dwData["EXTTECH"].ToString();
                    or1.Parameters.Add("FPRICE", OracleType.NVarChar).Value = dwData["FPRICE"].ToString();
                    or1.Parameters.Add("TQTY", OracleType.NVarChar).Value = dwData["TQTY"].ToString();
                    or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
                    or1.Parameters.Add("S", OracleType.NVarChar).Value = dwData["S"].ToString();
                    or1.Parameters.Add("M", OracleType.NVarChar).Value = dwData["M"].ToString();
                    or1.Parameters.Add("L", OracleType.NVarChar).Value = dwData["L"].ToString();
                    or1.Parameters.Add("XL", OracleType.NVarChar).Value = dwData["XL"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteICC_ABPOSFS(string client, string krs, string lfd)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_ABPOSFS WHERE  "
                      + "   KRS=:KRS AND  LFD=:LFD ";
            or1.Parameters.Add("KRS", OracleType.NVarChar).Value = krs;
            or1.Parameters.Add("LFD", OracleType.NVarChar).Value = lfd;
            Connect2Proxy(or1);
        }
    }
}
